package com.itheima.zuoye.zuoye3;

import com.itheima.simpledataformat.SimpleDateFormat;

import java.text.DateFormat;
import java.text.ParseException;
import java.time.LocalDate;
import java.time.Period;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) throws ParseException {
//        请从控制台分别接收两个“生日”，格式为：yyyy年MM月dd日，用程序比较两个生日表示的人的年龄大小关系并打印出结果;
        System.out.println("请输入第一个生日：格式为：yyyy年MM月dd日");
        Scanner sc = new Scanner(System.in);
        String birthday1 = sc.next();
        System.out.println("请输入第二个生日：");
        String birthday2 = sc.next();

        System.out.println("==========================================");
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy年MM月dd日");
        Date time1 = sdf.parse(birthday1);
        Date time2 = sdf.parse(birthday2);
        if (time1.before(time2)) {
            System.out.println("第一个大");
        }else if (time1.equals(time2)) {
                System.out.println("两个生日相同");
            }
        else {
            System.out.println("第二个大");
        }

        System.out.println("==========================================");
//        :再使用LocalDate+DateTimeFormatter+Period完成一
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy年MM月dd日");
        LocalDate ld1 = LocalDate.parse(birthday1,dtf);
        LocalDate ld2 = LocalDate.parse(birthday2,dtf);
        Period period = Period.between(ld1, ld2);
        if (period.isNegative()) {
            period = period.negated();
            System.out.printf("第一个人比第二个人大：%d岁%d个月%d天%n",
                    period.getYears(), period.getMonths(), period.getDays());
        } else if (period.isZero()) {
            System.out.println("两人同一天生日");
        } else {
            System.out.printf("第二个人比第一个人大：%d岁%d个月%d天%n",
                    period.getYears(), period.getMonths(), period.getDays());
        }





    }
}
